package server.utility;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Id implements Comparable<Id>, Serializable{
	private int id;
	private static int current=100;
	
	public static Id nextId(){
		return new Id(current++);
	}
	
	
	public Id(int d) {
		id=d;
	}

	public String toString(){
		return ""+id;
	}

	public int compareTo(Id o) {
		return o.id-id;
	}
	
	public boolean equals(Object o){
		if(o instanceof Id){
			return id==((Id)o).id;
		}
		return false;
	}
	
	public int hashCode(){
		return id;
	}
	
	private void readObject(ObjectInputStream in) throws IOException,
	ClassNotFoundException {
		int ver=in.readInt();
		
		switch(ver){
		
			case 1:{
				id = in.readInt();
				current = in.readInt();
			}
		}
	}
	
	private void writeObject(ObjectOutputStream out) throws IOException {
		out.writeInt(1); //version
		
		out.writeInt(id);
		out.writeInt(current);
			
		
	}
	
}
